﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessComponents.Managers
{
    class CustomerMgr : ICustomerMgr
    {
        WaterFrontEntities wfe = new WaterFrontEntities();


        #region ICustomerMgr Members

        public void SaveCustomer(Customer customer)
        {
            wfe.AddToCustomers(customer);
            wfe.SaveChanges();

        }

        public Customer GetCustomer(string username)
        {
            Customer a = wfe.Customers.FirstOrDefault(m => m.UserName == username);
            return a;
        }

        public void UpdateCustomer(Customer customer)
        {
            Customer a=wfe.Customers.FirstOrDefault(m=>m.UserName==customer.UserName);
            //a.UserId = customer.UserId;
            //a.UserName = customer.UserName;
            a.IDNO = customer.IDNO;
            a.Address = customer.Address;
            a.Gender = customer.Gender;
            a.TelephoneNO = customer.TelephoneNO;
            a.Salutation = customer.Salutation;
            wfe.SaveChanges();
        }


        public Guid SelectUserid(string username)
        {
           
            aspnet_Users a=wfe.aspnet_Users.FirstOrDefault(m=> m.UserName == username);
            return a.UserId;
        }

        public IList<Customer> GetAllCustomer()
        {
            IList<Customer> customers ;
            customers = (from Customer c in wfe.Customers select c).ToList();
            return customers;

        }

        #endregion
    }
}
